﻿using System;

using Microsoft.Xna.Framework;

namespace xEngine.Maths
{
    public struct Bounds2D : IRectangle
    {
        #region Member Variables

        private float _left;
        private float _bottom;
        private float _right;
        private float _top;

        #endregion

        #region Properties

        public float Left
        {
            get { return _left; }
        }
        public float Bottom
        {
            get { return _bottom; }
        }
        public float Right
        {
            get { return _right; }
        }
        public float Top
        {
            get { return _top; }
        }
        public float Width
        {
            get { return _right - _left; }
        }
        public float Height
        {
            get { return _top - _bottom; }
        }

        #endregion

        #region Constructors

        public Bounds2D(Vector3 bottomLeft, Vector3 topRight) : this(bottomLeft.X, bottomLeft.Z, topRight.X, topRight.Z) { }
        public Bounds2D(Vector2 bottomLeft, Vector2 topRight) : this(bottomLeft.X, bottomLeft.Y, topRight.X, topRight.Y) { }
        public Bounds2D(float left, float bottom, float right, float top)
        {
            _left = left;
            _right = right;
            _top = top;
            _bottom = bottom;
        }

        #endregion

        #region Functions

        public bool ContainsPoint(Vector3 point)
        {
            return ContainsPoint(point.X, point.Z);
        }
        public bool ContainsPoint(Vector2 point)
        {
            return ContainsPoint(point.X, point.Y);
        }
        public bool ContainsPoint(Point point)
        {
            return ContainsPoint(point.X, point.Y);
        }
        public bool ContainsPoint(float x, float y)
        {
            return x >= _left && x <= _right && y >= _bottom && y <= _top;
        }

        public override string ToString()
        {
            return "Bounds [" + _left + "," + _bottom + " - " + _right + "," + _top + "]";
        }

        #endregion
    }
}
